﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ViaConvert.Xml
{
    public class Converter
    {
        public static List<Model.Csv.AddressInfo> ToCsvModel(Model.Xml.AddressInfo models)
        {
            List<Model.Csv.AddressInfo> list = new List<Model.Csv.AddressInfo>();
            
            foreach (Model.Xml.City city in models.City)
            {
                Model.Csv.AddressInfo info = new Model.Csv.AddressInfo();
                
                foreach (Model.Xml.District district in city.District)
                {
                    
                    foreach (Model.Xml.Zip zip in district.Zip)
                    {
                        info.ZipCode = Convert.ToInt32(zip.code);
                        info.DistrictName = district.name;
                        info.CityName = city.name;
                        info.CityCode = city.code;
                        
                        list.Add(info);
                    }
                }
            }

            return list;
        }
    }
}
